<style>
    .time-range {
        margin-top: -28px;
        margin-left: 113px;
    }
    .time-range>span {
        height: 35px;
        line-height: 35px;
    }
</style>
<div class="modal-dialog" role="document" style="width:600px;">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="exampleModalLabel">设置航班 - <small>{$tripRow.ticket_id} - {$tripRow.real_name}</small></h4>
        </div>
        <form class="form-horizontal" style="padding:4%;height:375px;overflow-y:auto;" id="air-form">
            <input type="hidden" name="tripId" value="{$tripId}">
            <div class="tab-content" style="top:98px;">
                <include file="air_base" />
            </div>
        </form>
        <div class="modal-footer">
            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
            <button type="button" id="save" class="btn btn-primary">保存</button>
        </div>
    </div>
</div>
<div id="prop_template" style="display:none;">
    <div>
        <div class="form-group">
            <label class="control-label col-sm-2">航班号:</label>
            <div class="col-sm-8">
                <input class="form-control" name="air_code[]" value="" placeholder="请填写航班号" />
            </div>
            <button type="button" class="btn btn-primary" style="margin-left: 10px;" onclick="delName(this)">删除</button>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">始发地:</label>
            <div class="col-sm-8">
                <input class="form-control" name="origin[]" value="" placeholder="请填写始发地" />
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">目的地:</label>
            <div class="col-sm-8">
                <input class="form-control" name="destination[]" value="" placeholder="请填写目的地" />
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">出发日期:</label>
            <div class="col-sm-8">
                <div class="input-group date" id="depart_date_num">
                    <input type='text' value="" name="depart_date[]" class="form-control " data-date-format="yyyy-mm-dd hh:ii" />
                    <div class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">到达日期:</label>
            <div class="col-sm-8">
                <div class="input-group date" id="reach_date_num">
                    <input type='text' value="" name="reach_date[]" class="form-control " data-date-format="yyyy-mm-dd hh:ii" />
                    <div class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </div>
                </div>
            </div>
        </div>
        <hr />
    </div>
</div>
<script type="text/javascript">
    $(function () {
//        $("#depart_date").datetimepicker({
//            format: "yyyy-mm-dd hh:ii",
//            language: "ch",
//            pickDate: true,
//            pickTime: false,
//            autoclose: true,
//            minView: 0
//        }).on('hide',function(e) {
//            var bv = $('#air-form').data('bootstrapValidator');
//            if(bv){
//                bv.updateStatus('depart_date[]', 'NOT_VALIDATED',null).validateField('depart_date[]');
//            }
//        });
//        $("#reach_date").datetimepicker({
//            format: "yyyy-mm-dd hh:ii",
//            language: "ch",
//            pickDate: true,
//            pickTime: false,
//            autoclose: true,
//            minView: 0
//        }).on('hide',function(e) {
//            var bv = $('#air-form').data('bootstrapValidator');
//            if(bv){
//                bv.updateStatus('reach_date[]', 'NOT_VALIDATED',null).validateField('reach_date[]');
//            }
//        });

        $("#save").bind("click",doSave);
    });

    function doSave(){
        if(!validateForm()){
            return false;
        }
        $.ajax({
            url: "{:U('Admin/Airway/setAir')}",
            type: "post",
            dataType: "json",
            data: $("#air-form").serialize(),
            success: function (data) {
                if(data.status){
                    common.alert("提示",data.msg,function(){
                        common.reload();
                    });
                }else{
                    common.alert("提示",data.msg);
                }
            }
        });
    }

    function validateForm(){
        $('#air-form').bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                //invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                "air_code[]": {
                    validators: {
                        notEmpty: {
                            message: '航班号不能为空'
                        }
                    }
                },
                "origin[]": {
                    validators: {
                        notEmpty: {
                            message: '始发地不能为空'
                        }
                    }
                },
                "destination[]": {
                    validators: {
                        notEmpty: {
                            message: '目的地不能为空'
                        }
                    }
                },
                "depart_date[]": {
                    validators: {
                        notEmpty: {
                            message: '出发日期不能为空'
                        }
                    }
                },
                "reach_date[]": {
                    validators: {
                        notEmpty: {
                            message: '到达日期不能为空'
                        }
                    }
                },
            }
        });
        var data = $('#air-form').data('bootstrapValidator');
        if (data) {
            data.validate();
            if (!data.isValid()) {
                return false;
            }
        }
        return true;
    }

</script>